package jsyf.oa.dao.wreport;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.wreport.CostAuditEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by y on 2018/3/19.
 */
@Repository
public class CostAuditDao extends BaseDao{
    public CostAuditDao() {
        super.iBaseEntity = new CostAuditEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, CostAuditEntity.class);
    }

    public List<CostAuditEntity> getEntityListByCondition(String condition, Object[] params) {
        List<JSONObject> jsonList = getJSONListByCondition(condition, params);
        List<CostAuditEntity> entityList = new ArrayList<>();
        for (int i = 0; i < jsonList.size(); i++) {
            CostAuditEntity entity=(CostAuditEntity)convertJson2Entity(jsonList.get(i));
            entityList.add(entity);
        }
        return entityList;
    }
    public JSONObject getAuditFlag(String fkCostId){
         StringBuffer sql=new StringBuffer();
         sql.append(" SELECT");
         sql.append(" AUDIT_FLAG as auditFlag");
         sql.append(" FROM");
         sql.append(" t_wrt_cost_audit");
         sql.append(" WHERE FK_COST_ID =?");
         return super.queryForJsonObject(sql.toString(),new Object[]{fkCostId});
    }

}
